home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / WC40REC.ZIP;1 / WCUSERDB.DOC < prev   
Encoding:
Text File  |  1994-03-21  |  5.1 KB  |  117 lines

  1. Wildcat 4 User Database Notes
  2. -----------------------------
  3.  
  4. The user records are stored in a fixed length Filer database.  There
  5. are no variable length parts to a user record any more, so no matter
  6. how many conferences you have, a user record is the same size.
  7.  
  8. The variable length parts of the user record are stored in another file
  9. in the same directory called USERCONF.DAT.  This file has a small header:
  10.  
  11. type
  12.   TUserConfFileHeader = record
  13.     totalconfs : Word;     { total number of conferences }
  14.   end;
  15.  
  16. The header is at offset zero at the start of the file.  The remainder
  17. of the file contains either index pages or a data pages.  The index
  18. page has the following structure:
  19.  
  20. type
  21.   TUserConfIndex = record
  22.     RecLen  : Word;              { length of this record in bytes }
  23.     RecType : TUserConfRecType;  { ucrIndex record type id        }
  24.     offsets : array [0..31] of Longint;
  25.   end;
  26.  
  27. Not all of the 32 offsets are actually used - the number that are used
  28. is defined by the following function:
  29.  
  30.   function MaxPages(MaxConfAreas : Word) : Word;
  31.   const
  32.     MaxChunk = 1024;
  33.   begin
  34.     MaxPages := (LongInt(MaxConfAreas) + MaxChunk - 1) div MaxChunk;
  35.   end;
  36.  
  37. A data page has the following structure:
  38.  
  39. type
  40.   TUserConfData = record
  41.     cuFlags       : Byte;  { user's flags as defined in wctype.pas }
  42.     cuLastRead    : Word;  { last read message number              }
  43.     cuFirstUnread : Word;  { first unread message number           }
  44.   end;
  45.  
  46.   TUserConfPage = record
  47.     RecLen       : Word;             { length of this record in bytes  }
  48.     RecType      : TUserConfRecType; { ucrData record type id          }
  49.     UserID       : LongInt;          { user id number used by wcrepair }
  50.     Page         : Integer;          { page number of this page        }
  51.     This         : Longint;          { offset of this page in bytes    }
  52.     UserConfData : array [0..1023] of TUserConfData;
  53.   end;
  54.  
  55. The ConfUser array in TConfUserPage will not always be 1024 records long.
  56. The size of this structure is variable length depending on the number of
  57. conferences defined in Makewild and is computed according to the following
  58. function:
  59.  
  60.   function PageRecords(MaxConfAreas : Word) : Word;
  61.   const
  62.     MaxChunk = 1024;
  63.   var
  64.     Chunks : Word;
  65.   begin
  66.     Chunks := (LongInt(MaxConfAreas) + MaxChunk - 1) div MaxChunk;
  67.     PageRecords := ((LongInt(MaxConfAreas) + Chunks - 1) div Chunks);
  68.   end;
  69.  
  70. This function balances the space used by each record so the amount of wasted
  71. space is minimal.  So for 1024 conferences there will be one 1024 record
  72. page, but for 1025 conferences the pages will be split into two 513 record
  73. chunks, so there is only one wasted record.
  74.  
  75. There is a field called UserConfData in the fixed part of the user
  76. record which points to the offset of the index page for that user in
  77. USERCONF.DAT.  Wildcat always creates an index page for each new user
  78. added to the database, so you can assume this page exists.  However,
  79. not all of the data pages will exist so you have to take this into
  80. account and perhaps create pages as necessary (if a page does not exist
  81. its offset will be 0 in the index page).
  82.  
  83. New pages are always created at the end of the file and old pages (from
  84. a deleted user, for example) are not reused.  WcRepair will pack the
  85. USERCONF.DAT file and remove all unnecessary pages.
  86.  
  87. This is a diagram of how this setup might all fit together with 1025
  88. conferences (with 1024 or fewer conferences there is only one user data
  89. page so things are kind of degenerate):
  90.  
  91.      ALLUSERS.DAT         ofs       USERCONF.DAT
  92.  +-------------------+     0+----------------------------+
  93.  |                   |      | (header)                   |
  94.  .                   .      |                            |
  95.  .                   .     2+----------------------------+
  96.  |                   |      |                            |
  97.  +-------------------+      .                            .
  98.  | JOE USER          |      .                            .
  99.  | (user info)       |      |                            |
  100.  | UserConfData=50 ------>50+----------------------------+
  101.  +-------------------+      | 61                         | (index page
  102.  |                   |      | 2661                       | for JOE USER)
  103.  .                   .    61+----------------------------+
  104.                             | JOE USER, page=0, this=61  | (page 0 for JOE)
  105.                             | (513 TConfUser records)    |
  106.                         2661+----------------------------+
  107.                             | JOE USER, page=1, this=2661| (page 1 for JOE)
  108.                             | (513 TConfUser records)    |
  109.                         5261+----------------------------+
  110.                             |                            |
  111.                             .                            .
  112.  
  113. All writing or modification access to the USERCONF.DAT file should be done
  114. only while the ALLUSERS.DAT file is locked in Filer (using BTLockFileBlock).
  115. This is done to prevent having to lock a regular DOS file (which is a pain
  116. and is also different on various networks - Filer takes care of this).
  117.